package controllers;

import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.commons.lang.time.DateFormatUtils;

import com.google.gson.JsonObject;

import play.Logger;
import play.Play;
import play.mvc.Controller;

public class Files extends Controller {

	public static void upload(File file,String folder) throws IOException{
		Logger.debug("文件上传: %s", file.getName());
		String attachFolder = Play.configuration.getProperty("attachments.path");
		String extension = FilenameUtils.getExtension(file.getName());
		String newName = DateFormatUtils.format(new Date(), "yyyyMMddHHmmssSSS");
		newName += RandomStringUtils.randomNumeric(4);
		newName += "."+extension;
		File file2 = new File(attachFolder,newName);
		FileUtils.copyFile(file, file2);
		String prefix = Play.configuration.getProperty("attachments.download.prefix");
		
		renderText(newName);
	}
}
